import time
import pytest

from playwright.sync_api import sync_playwright


@pytest.fixture(scope='class')

def page():
    #初始化并打开后台
    with sync_playwright()as p:
        browser=p.firefox.launch(headless=False)
        page=browser.new_page()
        yield page
        time.sleep(3)
        page.close()

def test_jiuxian_01(page):
    page.goto('https://www.jiuxian.com/')
    #点击去登录
    page.click('xpath = /html/body/div[2]/div/div[1]/div/a[1]')
    time.sleep(4)
    #断言1：账号登录
    dy1=page.locator('xpath = //*[@id="loginform"]/div/div/div/div/div[1]/div[1]/a[1]').text_content()
    assert "帐号登录" == dy1
    #输入账号密码
    page.fill(selector='#userName',value='13381144084')
    page.fill(selector='#password',value='grq200566++')
    time.sleep(15)
    page.click('xpath=//*[@id="save"]')
    time.sleep(7)
    #断言2：
    dy2=page.locator('xpath = /html/body/div[2]/div/div[1]/div/p/span').text_content()
    assert "jxw782493824" == dy2
    page.fill(selector='#wd',value='五粮液')
    page.click('xpath=/html/body/div[4]/div/div[2]/div[1]/form/input[2]')
    time.sleep(3)
